package sqlanalysisgui.view.model;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.HashMap;
import java.util.Map;

import com.cho.core.util.StringUtils;

public class TableInfo implements Cloneable{
	private String tableName;
	private String tableComment;
	private String crudType;
	private String sourceLine;
	private String sourcePath;
	private String fileSeq;
	private String fileName;
	private Map<String, Integer> searchKeywrodAndSourceLine = new HashMap<String, Integer>();
	

	/*
	 * JFace Data Binding 은 자바오브젝트의 속성이 변했을 때 이를 감지하고 반응할 수 있도록 자기 자신을 이 속성의
	 * listener로 등록할 수 있다. SWT와 JFace Widget은 이것을 지원한다.
	 */
	private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(
			this);

	public TableInfo() {
		// TODO Auto-generated constructor stub
	}

	public TableInfo(String tableName, String crudType, String sourceLine,
			String sourcePath, String fileSeq) {
		super();
		this.tableName = tableName;
		this.crudType = crudType;
		this.sourceLine = sourceLine;
		this.sourcePath = sourcePath;
		this.fileSeq = fileSeq;
	}

	public TableInfo(String tableName, String tableComment) {
		super();
		this.tableName = tableName;
		this.tableComment = tableComment;
	}

	public TableInfo(String tableName, String crudType, String sourceLine,
			String sourcePath, String fileSeq, String fileName) {
		super();
		this.tableName = tableName;
		this.crudType = crudType;
		this.sourceLine = sourceLine;
		this.sourcePath = sourcePath;
		this.fileSeq = fileSeq;
		this.fileName = fileName;
	}

	public void addPropertyChangeListener(String propertyName,
			PropertyChangeListener listener) {
		propertyChangeSupport.addPropertyChangeListener(propertyName, listener);
	}

	public void removePropertyChangeListener(PropertyChangeListener listener) {
		propertyChangeSupport.removePropertyChangeListener(listener);
	}

	public String getTableName() {
		return tableName;
	}

	public void setTableName(String tableName) {
		propertyChangeSupport.firePropertyChange("tableName", this.tableName,
				this.tableName = tableName);
	}

	public String getCrudType() {
		return crudType;
	}

	public void setCrudType(String crudType) {
		propertyChangeSupport.firePropertyChange("crudType", this.crudType,
				this.crudType = crudType);
	}

	public String getSourceLine() {
		return sourceLine;
	}
	
	public int getSourceLineInteger() {
		if(StringUtils.isNotEmpty(sourceLine)){
			return Integer.parseInt(sourceLine);
		}else{
			return 0;
		}
	}

	public void setSourceLine(String sourceLine) {
		propertyChangeSupport.firePropertyChange("sourceLine", this.sourceLine,
				this.sourceLine = sourceLine);
	}

	public String getSourcePath() {
		return sourcePath;
	}

	public void setSourcePath(String sourcePath) {
		propertyChangeSupport.firePropertyChange("sourcePath", this.sourcePath,
				this.sourcePath = sourcePath);
	}

	public String getFileSeq() {
		return fileSeq;
	}

	public void setFileSeq(String fileSeq) {
		propertyChangeSupport.firePropertyChange("fileSeq", this.fileSeq,
				this.fileSeq = fileSeq);
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		propertyChangeSupport.firePropertyChange("fileName", this.fileName,
				this.fileName = fileName);
	}

	
	public String getTableComment() {
		return tableComment;
	}

	public void setTableComment(String tableComment) {
		propertyChangeSupport.firePropertyChange("tableComment", this.tableComment,
				this.tableComment = tableComment);
	}
	
	


	public Map<String, Integer> getSearchKeywrodAndSourceLine() {
		return searchKeywrodAndSourceLine;
	}

	public void setSearchKeywrodAndSourceLine(
			Map<String, Integer> searchKeywrodAndSourceLine) {
		this.searchKeywrodAndSourceLine = searchKeywrodAndSourceLine;
	}

	@Override
	public String toString() {
		return "TableInfo [tableName=" + tableName + ", tableComment="
				+ tableComment + ", crudType=" + crudType + ", sourceLine="
				+ sourceLine + ", sourcePath=" + sourcePath + ", fileSeq="
				+ fileSeq + ", fileName=" + fileName + "]";
	}
	
	
	@Override
	public Object clone() throws CloneNotSupportedException {
		// CHO Auto-generated method stub
		return super.clone();
	}

}
